﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPPD.model;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Linq;

namespace SPPD.controller
{
    class controller_transaksi
    {
        crud<transaksi> nhi;
        List<transaksi> trans;
        public controller_transaksi()
        {
            nhi = new crud <transaksi> ();
            trans = new List <transaksi> ();
        }
        public void insert(transaksi trans)
        {
            crud<transaksi> nhi = new crud<transaksi>();
            nhi.insert(trans);
        }
        public List<transaksi> load()
        {
            var factory = nhi.load();
            using (var session = factory.OpenSession())
            {
                var categories = session.Query<transaksi>()
                       .ToList();
                return categories;
            }
        }

        public void update(sppd sppd_update, string talasan, string tkoreksi, string tsaran)
        {
            var factory = nhi.load();
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var categories = session.Get<transaksi>(sppd_update);
                    categories.alasan = talasan;
                    categories.saran = tsaran;
                    categories.koreksi = tkoreksi;
                    transaction.Commit();
                }



            }
        }
        public string autogenerate()
        {
            trans = load();
            return "TR" + (trans.Count + 1);
        }
    }
}
